/**
 * Created with JetBrains PhpStorm.
 * User: Evan Hou
 * Date: 12-8-13
 * Time: 下午1:37
 * To change this template use File | Settings | File Templates.
 */
var pay = {

};

var oneCardNum        = new Array("snda", "sohu", "wanmei", "ztgame", "netease");
oneCardNum['snda']    = new Array("5","10","15","30","35","45","100","300","350","1000");
oneCardNum['sohu']    = new Array("5","10","15","30","40","100");
oneCardNum['ztgame']  = new Array("10", "15", "20", "25","30","50","60","100","300","468");
oneCardNum['netease'] = new Array("5","10","15","20","30","50");

//检查重复通行证
pay.checkRePassport = function (v)
{
    var userName = user.checkUserName(v);
    var reUserName = document.getElementById('re_username_id').value;

    $('#re_username_notice_id').html('输入正确');

    if ( !wq.isEmpty(reUserName) ) {
        $('#re_username_notice_id').html('<span style="color:red;">用户名为空。</span>');
        return false;
    }

    if ( !wq.limit_length(reUserName) ) {
        $('#re_username_notice_id').html('<span style="color:red;">用户名小于6或大于32个字符。</span>');
        return false;
    }

    if (userName != reUserName) {
        $('#re_username_notice_id').html('<span style="color:red;">两次输入不一致。</span>');
        return false;
    }

    return reUserName;
}

//检查输入金额
pay.checkAmount = function (values)
{
    var number    = values.value.replace(/[^\d]/g,'');
    var isDecimal = values.value.indexOf(".");
    var tyhb      = parseInt(values.value);
    if (number && number != 0)
    {
        if (isDecimal) { values.value = tyhb; }//是否包含小数点
    } else
    {
        var isOneCard  = document.getElementById('dk_list');
        if (isOneCard != null)
        {
            $('#amount_notice_id').html('<span style="color:red;">请选择游戏点卡！</span>');
        } else
        {
            $('#amount_notice_id').html('<span style="color:red;">请输入正整数，请使用半角字符！</span>');
        }
        values.value = '';
        return false;
    }

    $('#amount_notice_id').html('对应元宝：'+tyhb * 100);
    //$('#amount_notice_id').text(tyhb);
    return tyhb;
}

//提交充值
pay.submitPay = function (v)
{
    var userName = user.checkUserName(v);
    if ( !userName ) return;

    if ( !pay.checkRePassport(v) ) return ;

    if ( !user.isActivation() ) return ;


    var amount = document.getElementById('amount_id').value;
    $('#layer_amount_id').html(amount);
    $('#layer_username_id').html(userName);
    var payType = document.getElementById('pay_channels').value;

    var v = '';
    switch (payType) {
        case 'wsyh':v = '网上银行';break;
        case 'alipay':v = '支付宝';break;
        case 'yeepay':v = '易宝支付';break;
        case '99bill':v = '快钱支付';break;
        case 'szx':v = '神州行';break;
        case 'game_card':v = '游戏点卡';break;
        default :v = '网上银行';
    }
    $('#layer_pay_channel').html(v);
    document.getElementById('pay_confirm').style.display = '';
    //document.pay_form.submit();
}

pay.submit = function ()
{
    document.pay_form.submit();

    pay.closeDiv('pay_confirm');

    document.getElementById('pay_later').style.display = '';
}

pay.selectGameCard = function (v)
{
    var cardName = 'snda';
    var name = '';
    switch (v) {
        case 'snda' : cardName = 'snda'; name = '盛大'; break;
        case 'sohu' : cardName = 'sohu'; name = '搜狐'; break;
        case 'ztgame' : cardName = 'ztgame'; name = '征途'; break;
        case 'netease' : cardName = 'netease'; name = '网易'; break;
    }

    var card = oneCardNum[cardName];

    if ( !wq.isEmpty(card) ) {
        return false;
    }

    var html = '';
    for (var i = 0; i < card.length; i++) {
        html += '<option value="'+card[i]+'">'+name+card[i]+'元卡</option>';
    }

    $('#amount_id').html(html);
}

pay.closeDiv = function (i) {
    document.getElementById(i).style.display = 'none';
    //document.getElementById('bg').style.display = 'none';

    //document.getElementById('popIframe').style.display = 'none';
}